home *** CD-ROM | disk | FTP | other *** search
- /* Buttons.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
- #include <stdlib.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "WindowAids.h"
- #include "ControlUtils.h"
- #include "Dispatcher.h"
- #include "DDocData.h"
- #include "GadgetsEngine.h"
- #include "GadgetsDoc.h"
- #include "Buttons.h"
-
-
- static GadgetsEngine* GetEngine (Buttons* self);
-
- static void DoUndo (Buttons* self);
- static void DoCut (Buttons* self);
- static void DoCopy (Buttons* self);
- static void DoPaste (Buttons* self);
- static void DoClear (Buttons* self);
- static void DoSelectAll (Buttons* self);
- static void DoShowClipboard (Buttons* self);
-
-
- //----------
- Buttons* NewButtons ()
- {
- Buttons* window;
-
- window = (Buttons*)malloc (sizeof (Buttons));
- Buttons_Init (window);
- SetClassID (window, classButtons);
-
- return window;
- }
-
- //----------
- void DeleteButtons (
- Buttons* window)
- {
- Buttons_Free (window);
- free (window);
- }
-
- //----------
- void Buttons_Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- Buttons* winObj = NewButtons ();
-
- if (winObj != nil) {
- Buttons_Open (winObj, inDoc, inData);
- }
- }
-
- //----------
- void Buttons_Init (
- Buttons* self)
- {
- }
-
- //----------
- void Buttons_Free (
- Buttons* self)
- {
- }
-
- //----------
- GadgetsEngine* GetEngine (
- Buttons* self)
- {
- return (GadgetsEngine*) self->super.mDoc->mEngine;
- }
-
- /*----------*/
- void Buttons_Open (
- Buttons* self,
- AMDoc* inDoc,
- DDocData* inData)
- {
- WindowPtr window;
- Handle wftb;
-
- self->super.mDoc = inDoc;
- self->mData = inData;
- AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- window = GetWindow (WIND_Buttons);
- if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
- SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
- }
- self->super.mWindow = window;
- ((GadgetsDoc*)self->super.mDoc)->mButtonsPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) self);
- SetPort (window);
- SetInfo (window);
-
- wftb = GetResource ('Wftb', WIND_Buttons);
-
- CreateRootControl (window, &self->super.mRootControl);
-
- self->super.vScroll = nil;
- self->super.hScroll = nil;
-
-
- self->mStandardHandle = GetNewControl (CNTL_Standard, window);
- SetWindowItemFont (self->mStandardHandle, wftb, 1);
- SetDefaultState (self->mStandardHandle, true);
-
- self->mRightIconHandle = GetNewControl (CNTL_RightIcon, window);
- SetWindowItemFont (self->mRightIconHandle, wftb, 2);
-
- self->mBevelHandle = GetNewControl (CNTL_Bevel, window);
- SetWindowItemFont (self->mBevelHandle, wftb, 3);
- SetBevelButtonTextPlacement (self->mBevelHandle, kControlBevelButtonPlaceToRightOfGraphic);
- SetBevelButtonTextAlignment (self->mBevelHandle, kControlBevelButtonAlignTextFlushLeft, 0);
- SetBevelButtonGraphicAlignment (self->mBevelHandle, kControlBevelButtonAlignLeft, 0, 0);
-
- self->mXxHandle = GetNewControl (CNTL_Xx, window);
- SetWindowItemFont (self->mXxHandle, wftb, 4);
- SetControlValue (self->mXxHandle, GetTriangle (self->mData));
-
- self->mCapTriangleLabel = GetNewControl (CNTL_CapTriangle, window);
- SetWindowItemFont (self->mCapTriangleLabel, wftb, 5);
- SetControlFromTEXT (self->mCapTriangleLabel, TEXT_CapTriangle);
-
- self->mLightHandle = GetNewControl (CNTL_Light, window);
- SetWindowItemFont (self->mLightHandle, wftb, 6);
-
- self->mLeftRightHandle = GetNewControl (CNTL_LeftRight, window);
- SetWindowItemFont (self->mLeftRightHandle, wftb, 7);
- SetControlValue (self->mLeftRightHandle, GetLeftRight (self->mData));
-
- self->mRadiosBoxHandle = GetNewControl (CNTL_RadiosBox, window);
- SetWindowItemFont (self->mRadiosBoxHandle, wftb, 8);
- self->mRadiosGroupHandle = GetNewControl (CNTL_RadiosGroup, window);
- EmbedControl (self->mRadiosGroupHandle, self->mRadiosBoxHandle);
- self->mRadioButtonHandle = GetNewControl (CNTL_RadioButton, window);
- EmbedControl (self->mRadioButtonHandle, self->mRadiosGroupHandle);
- SetWindowItemFont (self->mRadioButtonHandle, wftb, 10);
- SetBevelButtonGraphicAlignment (self->mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
- self->mRadioButton2Handle = GetNewControl (CNTL_RadioButton2, window);
- EmbedControl (self->mRadioButton2Handle, self->mRadiosGroupHandle);
- SetWindowItemFont (self->mRadioButton2Handle, wftb, 11);
- SetBevelButtonGraphicAlignment (self->mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
-
- self->mInvisibleHandle = GetNewControl (CNTL_Invisible, window);
- SetWindowItemFont (self->mInvisibleHandle, wftb, 12);
-
- self->mCapInvisibleLabel = GetNewControl (CNTL_CapInvisible, window);
- SetWindowItemFont (self->mCapInvisibleLabel, wftb, 13);
- SetControlFromTEXT (self->mCapInvisibleLabel, TEXT_CapInvisible);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- /*----------*/
- void Buttons_Close (
- Buttons* self)
- {
- RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- ((GadgetsDoc*)self->super.mDoc)->mButtonsPtr = nil;
- SetInfo (nil);
- HideWindow (self->super.mWindow);
- DisposeWindow (self->super.mWindow);
-
- DeleteButtons (self);
- }
-
- /*----------*/
- void Buttons_Track (
- Buttons* self,
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- if (whichControl == self->mStandardHandle) {
- if (TrackClick (self->mStandardHandle, where)) {
- }
- }
- if (whichControl == self->mRightIconHandle) {
- if (TrackClick (self->mRightIconHandle, where)) {
- }
- }
- if (whichControl == self->mBevelHandle) {
- if (TrackClick (self->mBevelHandle, where)) {
- }
- }
- if (whichControl == self->mXxHandle) {
- if (TrackCheckbox (self->mXxHandle, where)) {
- SetTriangle (self->mData, GetControlValue (self->mXxHandle) != 0);
- }
- }
- if (whichControl == self->mLightHandle) {
- if (TrackClick (self->mLightHandle, where)) {
- }
- }
- if (whichControl == self->mLeftRightHandle) {
- if (TrackCheckbox (self->mLeftRightHandle, where)) {
- SetLeftRight (self->mData, GetControlValue (self->mLeftRightHandle) != 0);
- }
- }
- if (whichControl == self->mRadiosGroupHandle) {
- if (TrackClick (whichControl, where) != 0) {
- SetRadios (self->mData, GetControlValue (self->mRadiosGroupHandle));
- }
- }
- if (whichControl == self->mInvisibleHandle) {
- if (TrackClick (self->mInvisibleHandle, where)) {
- }
- }
- }
-
- //----------
- void Buttons_DataChanged (
- Buttons* self,
- long inDataID)
- {
- if (inDataID == idTriangle) {
- SetControlValue (self->mXxHandle, GetTriangle (self->mData));
- }
- if (inDataID == idLeftRight) {
- SetControlValue (self->mLeftRightHandle, GetLeftRight (self->mData));
- }
- if (inDataID == idRadios) {
- SetControlValue (self->mRadiosGroupHandle, GetRadios (self->mData));
- }
- }
-
- /*----------*/
- void Buttons_MouseIn (
- Buttons* self,
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void Buttons_ExitCurField (
- Buttons* self)
- {
- ControlHandle focus;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- /*----------*/
- void Buttons_TypeIn (
- Buttons* self,
- char ch)
- {
- ControlHandle focus;
- short keyCode;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- Buttons_ExitCurField (self); // Dispatch
- SimulateClick (self->mStandardHandle);
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = curEvent.message & keyCodeMask;
- HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- } else {
- SysBeep (1);
- }
- }
-
- /*----------*/
- void Buttons_Resize (
- Buttons* self)
- {
- /* application-specific code to resize items in window */
- }
-
- /*----------*/
- void Buttons_Scroll (
- Buttons* self,
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == self->super.vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void DoUndo (
- Buttons* self)
- {
- } // DoUndo
-
- //----------
- void DoCut (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECut (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void DoCopy (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void DoPaste (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEPaste (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoPaste
-
- //----------
- void DoClear (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEDelete (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoClear
-
- //----------
- void DoSelectAll (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void DoShowClipboard (
- Buttons* self)
- {
- } // DoShowClipboard
-
- //----------
- Boolean Buttons_DoCommand (
- Buttons* self,
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo (self);
- break;
- case cmdCut:
- DoCut (self);
- break;
- case cmdCopy:
- DoCopy (self);
- break;
- case cmdPaste:
- DoPaste (self);
- break;
- case cmdClear:
- DoClear (self);
- break;
- case cmdSelectAll:
- DoSelectAll (self);
- break;
- case cmdShowClipboard:
- DoShowClipboard (self);
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-